package com.prothink.controller.statistics;

import com.prothink.entity.ProductSearchVolume;
import com.prothink.service.ProductSearchVolumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *商品搜索量控制层
 * @Date 2022 11 24
 */
@CrossOrigin
@Controller
@RequestMapping("ProductSearchVolume")
public class ProductSearchVolumeController {
    @Autowired
    private ProductSearchVolumeService productSearchVolumeService;

    /**
     * 获取全部被搜索过的商品
     * @param productSalesVolume 商品搜索量实体类
     * @return 所有被搜索过的商品
     */
    @ResponseBody
    @RequestMapping("/getProductSearchVolume")
    public List getProductSearchVolume(ProductSearchVolume productSearchVolume){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        try {
            Date parse = simpleDateFormat.parse(format);
            productSearchVolume.setSearchTime(parse);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return productSearchVolumeService.getProductSearchVolume(productSearchVolume);
    }

    /**
     * 添加被搜索的商品信息
     * @param productSalesVolume 商品搜索量实体类
     * @return
     */
    @ResponseBody
    @RequestMapping("/addProductSearchVolume")
    public Integer addProductSearchVolume(ProductSearchVolume productSearchVolume){
        return productSearchVolumeService.addProductSearchVolume(productSearchVolume);
    }

}
